// 全局返回地址
var global_back_url = (document.referrer === '') ? "/index/index" : document.referrer;
// 全局alert
var ck_alert = function (msg, callback) {
    var modal_div = $('#global-alert-modal');
    $('.am-modal-bd', modal_div).html(msg);
    if (callback){
        $('.am-close', modal_div).addClass('am-hide');
        $('.am-modal-footer', modal_div).removeClass('am-hide');
    }else{
        $('.am-close', modal_div).removeClass('am-hide');
        $('.am-modal-footer', modal_div).addClass('am-hide');
    }
    modal_div.modal({
        'closeViaDimmer':false,
        'onConfirm':function (option) {
            if (callback){
                callback();
            }
        }
    });
};
// 全局confirm
var ck_confirm = function (msg, confirm_callback, cancel_callback) {
    $('#global-confirm-modal').modal({
        onConfirm: function(options) {
            if (confirm_callback){
                confirm_callback();
            }
        },
        // closeOnConfirm: false,
        onCancel: function() {
            if (cancel_callback){
                cancel_callback();
            }
        }
    });
};
// ajax执行成功后执行方法
var ajax_success_func = function (res) {
    var callback = null;
    if (res.status == 1){
        callback = function () {
            if (res.data && res.data.go_url){
                location.href = res.data.go_url;return;
            }
            if (res.data && res.data.go_back){
                location.href = global_back_url;return;
            }
            location.reload();return;
        };
    }
    ck_alert(res.msg, callback);
};
// 删除表格中的一行数据
var del_tr_data = function(url){
    ck_confirm('确定要删除吗？', function () {
        $.ajax({
            url:url,
            dataType:'json',
            success:ajax_success_func
        });
    });
};
$(function () {
    // 全局返回按钮
    $('#btn_return').on('click',function () {
        location.href = global_back_url;
    });
});

